<template>
	<view class="mine tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar :isBack="false">益用管家</tn-nav-bar>
		<!-- 顶部自定义导航 -->

		<view class="top-backgroup">
			<image src='/static/my-bg4.png' mode='aspectFill' class='backgroud-image'>
			</image>
		</view>
		<view class="about__wrap" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<!-- 图标logo/头像 -->
			<view class="tn-flex tn-flex-col-top tn-margin-xs  " style="margin-top: -450rpx;">
				<view class="" @click="prew">
					<image class="logo-image" :src="xduser.face" mode="aspectFill"></image>
				</view>
				<view class="tn-padding-left-sm books">
					<view class="tn-flex tn-flex-row-between tn-flex-col-between myli">
						<view class="justify-content-item">
							<text class="tn-text-bold tn-padding-right-xs">{{xduser.username}}</text>
							<text class="tn-padding-right-xs">{{xduser.gsxz}}</text>
							<text class="tn-padding-right-xs">{{xduser.xb}}</text>
						</view>
					</view>
					<view class="myli" v-if="xduser.fcfl">
						<text class="">{{xduser.fcfl}}</text>
					</view>
					<view class="myli" v-if="xduser.iphone">
						<text class="">{{xduser.iphone}}</text>
					</view>
					<view class="myli" v-if="xduser.sfz">
						<text class="">{{xduser.sfz}}</text>
					</view>
					<view class="myli">
						<text class="">{{xduser.county}}{{xduser.street}}{{xduser.village}}</text>
					</view>
				</view>
			</view>

			<!-- 菜单-->
			<view class="about-shadow menu tn-margin-top-lg tn-padding-top-sm tn-padding-bottom-sm tn-bg-white">
				<view class="tn-flex tn-flex-wrap tn-flex-row-left tn-radius tn-padding-top">
					<!-- #ifdef MP-WEIXIN -->
					<view class="mli" @click="tn('/discoveryPages/leave/add')">
						<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
							<image class="micon" src="/static/icon/4.jpg"></image>
							<view class="tn-text-center">
								<text class="tn-text-ellipsis">请假</text>
							</view>
						</view>
					</view>
					<view class="mli" @click="gomini">
						<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
							<image class="micon" src="/static/icon/5.jpg"></image>
							<view class="tn-text-center">
								<text class="tn-text-ellipsis">云戒</text>
							</view>
						</view>
					</view>
					<view class="mli" @click="tn('/discoveryPages/sign/add')">
						<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
							<image class="micon" src="/static/icon/9.jpg"></image>
							<view class="tn-text-center">
								<text class="tn-text-ellipsis">签到</text>
							</view>
						</view>
					</view>
					<!--  #endif-->


					<view class="mli" @click="tn('/discoveryPages/userdetail')">
						<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
							<image class="micon" src="/static/icon/3.jpg"></image>
							<view class="tn-text-center">
								<text class="tn-text-ellipsis">用户信息</text>
							</view>
						</view>
					</view>
					<template v-if="ysshow">
						<view class="mli" v-if="xduser.again==1">
							<view v-show="faceimg"
								class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<image class="micon" src="/static/icon/11.jpg"></image>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">采集头像</text>
								</view>
							</view>

							<view v-show="!faceimg">
								<tn-image-upload ref="upload" :formData="formData" :action="action" @on-error="uperror"
									:customBtn="true" :isdd="isdd" :autoUpload="!!1" @on-change="upchange"
									@on-success="upsuccess" @on-choose-complete="choosecomplete"
									:showUploadList="setting.showUploadList" :sourceType="setting.sourceType">
									<view slot="addBtn"
										class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
										<image class="micon" src="/static/icon/11.jpg"></image>
										<view class="tn-text-center">
											<text class="tn-text-ellipsis">采集头像</text>
										</view>
									</view>
								</tn-image-upload>
							</view>
						</view>
						<!-- <view @click="test"> 测试采集</view> -->
						<view class="mli" @click="tn('/discoveryPages/urinecheck/list')">
							<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<image class="micon" src="/static/icon/1.jpg"></image>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">尿检记录</text>
								</view>
							</view>
						</view>
						<view class="mli" @click="tn('/discoveryPages/hair/list')">
							<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<image class="micon" src="/static/icon/2.jpg"></image>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">发检记录</text>
								</view>
							</view>
						</view>
						<view class="mli" @click="tn('/discoveryPages/interview/list')">
							<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<image class="micon" src="/static/icon/8.jpg"></image>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">走访记录</text>
								</view>
							</view>
						</view>
						<view class="mli" @click="tn('/discoveryPages/leave/list')">
							<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<image class="micon" src="/static/icon/10.jpg"></image>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">请假记录</text>
								</view>
							</view>
						</view>
						<view class="mli" @click="tn('/discoveryPages/sign/list')">
							<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
								<image class="micon" src="/static/icon/7.jpg"></image>
								<view class="tn-text-center">
									<text class="tn-text-ellipsis">签到记录</text>
								</view>
							</view>
						</view>
					</template>
					<view class="mli" @click="tn('/discoveryPages/physical/list')">
						<view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
							<image class="micon" src="/static/icon/tj.png"></image>
							<view class="tn-text-center">
								<text class="tn-text-ellipsis">体检记录</text>
							</view>
						</view>
					</view>
				</view>
			</view>


		</view>

		<view class='tn-tabbar-height'></view>

	</view>
</template>
<script>
	import {
		mapGetters,
		mapState
	} from "vuex";
	export default {
		name: 'userinfo',
		data() {
			return {
				xduser: '',
				id: '',
				faceimg: '',
				setting: {
					sourceType: ['camera'],
					showUploadList: false
				},
				action: this.$api.upload.index,
				formData: {},
				// #ifndef MP-WEIXIN
				isdd: true,
				// #endif

				// #ifdef MP-WEIXIN
				isdd: false,
				// #endif
			}
		},

		onLoad(options) {
			this.id = options.id ? options.id : this.id;
		},
		onShow() {
			if (!this.userinfo) {
				this.$user.getInfo()
			}
			//获取在册人员信息
			this.getxduser()
		},
		computed: {
			...mapState({
				userinfo: state => state.userinfo,
			}),

			ysshow() {
				return this.userinfo.usergroup != 'ys'
			}
		},
		methods: {
			// test(){
			// 	this.upsuccess({url:'https://apitest.ainan.net/jdgk/api/photo/face/202382516497-0277.jpg'})
			// },
			upsuccess(e) {
				let t = this;
				t.faceimg = e.url
				if (!t.faceimg) {
					this.$t.message.loading('获取图片失败，请重试')
					return
				}
				this.$t.message.loading('修改中')
				this.$request({
					url: this.$api.xduser.edit,
					method: 'POST',
					data: {
						face: t.faceimg,
						mfid: t.id,
					}
				}).then(response => {
					t.$t.message.closeLoading()
					if (response.code === 0) {
						// t.xduser.face = t.faceimg
						t.$t.message.toast('更新成功')
						t.getxduser(false)
					} else {
						t.$refs.upload.clear()
						t.$t.message.toast(response.msg)
					}
				}).catch(err => {
					t.faceimg = ''
					t.$t.message.closeLoading();
					t.$refs.upload.clear()
				})
			},
			uperror(e) {
				this.faceimg = '';
				this.$t.message.toast(e.msg)
			},
			gomini() {
				// let t = this;
				// uni.navigateToMiniProgram({
				// 	appId: 'wx2caa1d38f555eec1',
				// 	path: `pages/index/index?areacode=${t.userinfo.areacode}&userId=${t.userinfo.id}&sex=${t.userinfo.xb}&pinyin=${t.userinfo.areacode}&birthday=${t.userinfo.areacode}&appid=wx687df74d67d87138&idcard=${t.userinfo.idcard}&place=${t.userinfo.place}&name=${t.userinfo.username}`,
				// 	success(res) {
				// 		// 打开成功
				// 	}
				// })
			},
			// 跳转
			tn(url) {
				uni.navigateTo({
					url: `${url}?mfid=${this.id}&checkname=${this.xduser.username}`,
				});
			},
			prew() {
				uni.previewImage({
					urls: [this.xduser.face]
				})
			},
			//获取在册人员信息
			getxduser(showloading=true) {
				let t = this;
				if(showloading){
					t.$t.message.loading('加载中')
				}
				this.$request({
					url: this.$api.xduser.info,
					data: {
						mfid: t.id
					},
					method: 'POST'
				}).then(response => {
					t.$t.message.closeLoading();
					if (response.code === 0) {
						t.xduser = response.info;
					}
				}).catch(err=>{
					t.$t.message.closeLoading();
				});
			},
		}
	}
</script>


<style lang="scss" scoped>
	.mine {
		max-height: 100vh;
	}

	.myli {
		padding-bottom: 10rpx;
		font-size: 32rpx;
	}

	.box {
		padding: 15rpx;

	}

	/* 页面 end*/
	.micon {
		width: 80rpx;
		height: 80rpx;
		border-radius: 10rpx;
		margin-bottom: 10rpx;
	}

	.books {
		width: 100%;
		height: 260rpx;
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
	}

	/* 底部安全边距 start*/
	.tn-tabbar-height {
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}




	.tn-margin-xs1 {
		min-width: 170rpx;
	}

	.title {
		padding: 26rpx 30rpx;
	}

	/* 自定义导航栏内容 start */
	.custom-nav {
		height: 100%;

		&__back {
			margin: auto 5rpx;
			font-size: 40rpx;
			margin-right: 10rpx;
			flex-basis: 5%;
			width: 100rpx;
			position: absolute;
		}
	}



	/* 用户头像 start */
	.logo-image {
		width: 190rpx;
		height: 250rpx;
		border-radius: 5%;
		border: 1rpx solid rgba(255, 255, 255, 0.05);
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
	}

	/* 页面 start*/
	.about-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	.about {

		&__wrap {
			position: relative;
			z-index: 1;
			margin: 20rpx 30rpx;
		}

	}

	.menu {
		margin-top: 60rpx;
	}

	/* 页面 end*/

	.icon {
		width: 45rpx;
		height: 45rpx;
		margin-bottom: 20rpx;

		image {
			width: 45rpx;
			height: 45rpx;
		}
	}

	.mli {
		padding: 20px 10px;
		width: 25%;
	}

	.list {
		&__left {
			display: flex;
			align-items: center;
			justify-content: flex-start;

			&__icon,
			&__image {
				margin-right: 18rpx;
			}
		}

		&__right {
			display: flex;
			align-items: center;
			justify-content: flex-end;
		}
	}

	.list-icon-text,
	.list-image-text {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	/* 顶部背景图 start */
	.top-backgroup {
		height: 450rpx;
		z-index: -1;

		.backgroud-image {
			width: 100%;
			height: 750rpx;
			// z-index: -1;
		}
	}

	/* 顶部背景图 end */
</style>